﻿@{
    ViewBag.Title = "Stock Maintenance";
    ViewBag.Header = "Stock";
    ViewBag.Caption = "Maintenance";
    ViewBag.BackUrl = Url.Action("Index", "Stock");
    LineFocus.Nikcron.Models.Lookup Brands = ViewBag.Brands;
    LineFocus.Nikcron.Models.Lookup Models = ViewBag.Models;
    LineFocus.Nikcron.Models.Lookup Stockhouses = ViewBag.Stockhouses;
}

@using (Html.BeginForm("AddStock", "Stock", FormMethod.Post, new { onsubmit = "return ValidateForm();" }))
{
    <div class="col-md-12">

        <div class="box box-danger">
            <div class="box-body">
                
                <div class="form-group">
                    <label> Stockhouse:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <select id="Stockhouse" name="Stockhouse" class="selectpicker">
                            @Html.Partial("Dropdown", Stockhouses)
                        </select>
                    </div><!-- /.input group -->
                </div><!-- /.form group -->
                
                <div class="form-group">
                    <label>Date:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class="fa fa-calendar"></i>
                        </div>
                        <input type="text" id="StockDate" name="StockDate" class="form-control bfh-datepicker" value="@DateTime.Today.ToShortDateString()" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->   
                
                <div class="form-group">
                    <label> Brand:</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <select id="Manufacture" name="Manufacture" class="selectpicker">
                            @Html.Partial("Dropdown", Brands)
                        </select>
                    </div><!-- /.input group -->
                </div><!-- /.form group -->


                <div class="form-group">
                    <label> Model:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <select id="Model" name="Model" class="selectpicker" data-hide-disabled="true">
                            @Html.Partial("Dropdown", Models)
                        </select>
                    </div><!-- /.input group -->
                </div><!-- /.form group -->              

                <div class="form-group">
                    <label> Unit Price:</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="UnitPrice" name="UnitPrice" type="number" maxlength="100" class="form-control pull-right" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">                   
                    <label> IMEI #1:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="IMEIno1" name="IMEIno1" maxlength="50" type="text" class="form-control" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">                    
                    <label> IMEI #2:</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="IMEIno2" name="IMEIno2" maxlength="50" type="text" class="form-control" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->

                <div class="form-group">                   
                    <label> Serial #:</label><span class="astrisk">*</span>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class=""></i>
                        </div>
                        <input id="SerialNo" name="SerialNo" maxlength="50" type="text" class="form-control" />
                    </div><!-- /.input group -->
                </div><!-- /.form group -->    
                <div class="box-footer">
                    <button type="submit" class="btn btn-primary" style=" width:80px;">Save</button>
                    <button type="reset" class="btn btn-primary" style=" width:80px;">Cancel</button>
                </div>   
            </div><!-- /.box-body -->
        </div><!-- /.box -->
    </div><!-- /.col (left) -->
    
      <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">Stocks (In House) List</h3>
            </div>
            <div class="box-body table-responsive">
                <table id="dt_Grid" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Stockhouse</th>
                            <th>Product</th>
                            <th>IMEI# 1</th>
                            <th>IMEI# 2</th>
                            <th>Serial#</th>
                            <th>&nbsp;</th>
                        </tr>
                    </thead>
                    <tbody id="dt_Rows"></tbody>
                </table>
            </div><!-- /.box-body -->
        </div><!-- /.box -->
    </div>
}

<script id="dataTable_Grid" type="text/x-jquery-tmpl">
    <tr>
        <td>${Stockhouse}</td>
        <td>${Brand} (${ProductType}) - ${Model}</td>
        <td>${IMEI1}</td>
        <td>${IMEI2}</td>
        <td>${SerialNo}</td>
        <td><a href='@Url.Action("Delete")?Id=${Id}'>Delete</a></td>
    </tr>
</script>

<script type="text/javascript">
        $(document).ready(function () {
            $.getJSON('@Url.Action("GetStocks", "Stock")?Status=@LineFocus.Nikcron.Common.StockStatus.InHouse.ToString()', function (result) {
                $.tmpl($('#dataTable_Grid'), result).appendTo('#dt_Rows');
                $('#dt_Grid').dataTable({
                    "bPaginate": true,
                    "bLengthChange": true,
                    "bFilter": true,
                    "bSort": true,
                    "bInfo": true,
                    "bAutoWidth": false
                });
            });
        });

        $('#Model').change(function () {
            var url = '@Url.Action("GetPriceDetailsByModelId", "Product")?ModelId=';
            url += $('#Model').val();
            $.getJSON(url, function (result) {
                $('#UnitPrice').val(result);
            });
        })
</script>

<script>

    $(document).ready(function () {
        $('.selectpicker').selectpicker();
        $('#StockDate').datepicker();

        $('#Stockhouse')[0].selectedIndex = -1;
        $('*[data-id="Stockhouse"]').prop("title", "");
        $('*[data-id="Stockhouse"]').html('<span class="filter-option pull-left" />&nbsp;<span class="caret" />');

        $('#Manufacture')[0].selectedIndex = -1;
        $('*[data-id="Manufacture"]').prop("title", "");
        $('*[data-id="Manufacture"]').html('<span class="filter-option pull-left" />&nbsp;<span class="caret" />');

        $('#Model')[0].selectedIndex = -1;
        $('*[data-id="Model"]').prop("title", "");
        $('*[data-id="Model"]').html('<span class="filter-option pull-left" />&nbsp;<span class="caret" />');
    });

    $('#Manufacture').change(function () {
        $('.Manufacture').removeAttr("disabled");
        $('.Manufacture').prop("disabled", "true");
        $('.Manufacture_' + $('#Manufacture').val()).removeAttr("disabled");
        $('#Model').removeAttr("disabled");
        $('#Model').selectpicker('deselectAll');
        $('#Model').selectpicker("render");
        $('#Model').selectpicker("refresh");
        $('#Model')[0].selectedIndex = -1;
        $('*[data-id="Model"]').prop("title", "");
        $('*[data-id="Model"]').html('<span class="filter-option pull-left" />&nbsp;<span class="caret" />');
    });

    function ValidateForm() {
        RequiredDropdown("Stockhouse", -1, "Select a Stockhouse");
        RequiredTextbox("StockDate", "Enter Stock-In Date");
        RequiredDropdown("Model", -1, "Select a Model");
        RequiredTextbox("IMEIno1", "Enter the IMEI #1");
        RequiredTextbox("SerialNo", "Enter the Serial #");
        return AlertError();
    }
</script>